﻿using System;
using System.Collections.Generic;
using Rabbit.Logic;
using Raven.Client;

namespace ConsoleApplication1
{
    class rabbitCreate
    {
        public static void CreateProduct(IDocumentStore store)
        {

            using (IDocumentSession session = store.OpenSession()) // opens a session that will work in context of 'DefaultDatabase'
            {
                Product item = new Product
                {
                    Id = "product/" + 1.ToString("000000"),
                    Name = "malakaotu",
                    PricePerUnit = 60.00m,
                    NetWeight = 1000,
                    GrossWeight = 1100,
                    ProductionDate = DateTime.Now,
                    //Description = "mala"
                };

                session.Store(item); // stores employee in session, assigning it to a collection `Employees`

                session.SaveChanges(); // sends all changes to server
            }

        }

        public static void CreateCustomer(IDocumentStore store)
        {
            using (IDocumentSession session = store.OpenSession()) // opens a session that will work in context of 'DefaultDatabase'
            {
                Customer item = new Customer
                {
                    Id = "customer/" + 1.ToString("000000"),
                    Name = "John",
                    CellPhone = "13912345678",
                    TotalScore = 0,
                    DefaultAddressIndex = 0,
                    AddressList = new List<Address>() { new Address { Id = "customer/" + 1.ToString("000000"), City = "beijing", Region = "chaoyang", Detail = "hepingxijie", ContactName = "Jim", ContactPhone = "13912345678" } }
                };

                session.Store(item); // stores employee in session, assigning it to a collection `Employees`

                session.SaveChanges(); // sends all changes to server
            }
        }

        //public static void CreateOrder(IDocumentStore store)
        //{
        //    using (IDocumentSession session = store.OpenSession()) // opens a session that will work in context of 'DefaultDatabase'
        //    {
        //        Order item = new Order
        //        {
        //            Id = "order/" + 1.ToString("000000"),
        //            CustomerId = "customer/000001",
        //            ShipTo = new Address { Id = "customer/" + 1.ToString("000000"), City = "beijing", Region = "chaoyang", Detail = "hepingxijie", ContactName = "Jim", ContactPhone = "13912345678" },
        //            OrderedAt = DateTime.Now,
        //            RequireAt = DateTime.Now,
        //            //ShippedAt = DateTime.Now,
        //            State = OrderState.Received,
        //            Items = new List<OrderCartItem>() { new OrderCartItem() { ProductId = "product/" + 1.ToString("000000"), Quantity = 2 } }
        //        };

        //        session.Store(item); // stores employee in session, assigning it to a collection `Employees`

        //        session.SaveChanges(); // sends all changes to server
        //    }
        //}


        public static void UpdateProduct(IDocumentStore store )
        {

            using (IDocumentSession session = store.OpenSession()) // opens a session that will work in context of 'DefaultDatabase'
            {
                Product item = session.Load<Product>("products/1");
                item.Description = @"";

                session.Store(item); // stores employee in session, assigning it to a collection `Employees`

                session.SaveChanges(); // sends all changes to server
            }

        }
    }





}
